/**
 * Created by hhshi on 13-10-23.
 */
var user_model = require('../model/user');
/**
 * 用户注册页面入口
 * @param req
 * @param res
 */
exports.register = function(req, res){
    res.render('register', { title: '网盘注册' });
};

/**
 * 检测用户名是否存在
 * @param req
 * @param res
 */
exports.checkUserName = function(req, res){
    user_model.checkUserName(req.body.name, function(result){
        if(result.length > 0){
            res.send(false);
        }else{
            res.send(true);
        }
    });
};

/**
 * 提交注册信息
 * @param req
 * @param res
 */
exports.submitRegister = function(req, res){
    var newuser = {};
    newuser.name = req.body.name;
    newuser.password = req.body.password;
    newuser.email = req.body.email;
    newuser.address = req.body.address;

    user_model.addNewUser(newuser,function(result){
        res.json(result);
    })
};